package com.cbb.display.util;

import com.cbb.display.entity.TodayUserConfig;

import java.awt.font.TextHitInfo;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Random;
import java.util.UUID;

/**
 * @author: ljj
 * @description: 生成随机码的工具类
 * @date: 2017/10/26 14:20
 */
public class RandomUtil {
    /**
     * 生成前缀+32位编码 用作id
     *
     * @return string
     */
    public static String genarateId(String prefix) {
        String uuid = prefix + UUID.randomUUID().toString().trim().replaceAll("-", "");
        return uuid;
    }
    /**
     * 按照rdm的浮点数的数组来作为概率
     * @param rdm
     * @return
     */
   
  
    
   /** 
   * Math.random()产生一个double型的随机数，判断一下 
   * 例如0出现的概率为%50，则介于0到0.50中间的返回0 
     * @return int 
     *
    * @param todayUserConfig
    */
   public static int UserPercentageRandom(TodayUserConfig todayUserConfig)
   { 
	   /** 
	     * 0出现的概率
	     */
	  double rate0 = (double)todayUserConfig.getPer0()/100;
	   /** 
	     * 1出现的概率
	     */
	    double rate1 = (double)todayUserConfig.getPer1()/100;
	   /** 
	     * 2出现的概率
	     */
	   double rate2 = (double)todayUserConfig.getPer2()/100;
	   /** 
	     * 3出现的概率
	     */
	   double rate3 = (double)todayUserConfig.getPer3()/100;
	   /** 
	     * 4出现的概率
	     */
	    double rate4 = (double)todayUserConfig.getPer4()/100;
	   /** 
	     * 5出现的概率
	     */
	   double rate5 = (double)todayUserConfig.getPer5()/100;
   double randomNumber; 
   randomNumber = Math.random(); 
   if (randomNumber >= 0 && randomNumber <= rate0) 
   { 
    return 0; 
   } 
   else if (randomNumber >= rate0 && randomNumber <= rate0 + rate1) 
   { 
    return 1; 
   } 
   else if (randomNumber >= rate0 + rate1 
    && randomNumber <= rate0 + rate1 + rate2) 
   { 
    return 2; 
   } 
   else if (randomNumber >= rate0 + rate1 + rate2 
    && randomNumber <= rate0 + rate1 + rate2 + rate3) 
   { 
    return 3; 
   } 
   else if (randomNumber >= rate0 + rate1 + rate2 + rate3 
    && randomNumber <= rate0 + rate1 + rate2 + rate3 + rate4) 
   { 
    return 4; 
   } 
   else if (randomNumber >= rate0 + rate1 + rate2 + rate3 + rate4 
    && randomNumber <= rate0 + rate1 + rate2 + rate3 + rate4 
     + rate5) 
   { 
    return 5; 
   } 
   return -1; 
   } 
   public static int OrderPercentageRandom() 
   { 
	   /** 
	     * 0出现的概率为%50 
	     */
	   double rate0 = 0.30; 

	   double rate1 = 0.20; 

	   double rate2 = 0.15; 

	   double rate3 = 0.15; 

	   double rate4 = 0.10; 

	   double rate5 = 0.10; 
   double randomNumber; 
   randomNumber = Math.random(); 
   if (randomNumber >= 0 && randomNumber <= rate0) 
   { 
    return 0; 
   } 
   else if (randomNumber >= rate0 && randomNumber <= rate0 + rate1) 
   { 
    return 1;
   } 
   else if (randomNumber >= rate0 + rate1 
    && randomNumber <= rate0 + rate1 + rate2) 
   { 
    return 5;
   } 
   else if (randomNumber >= rate0 + rate1 + rate2 
    && randomNumber <= rate0 + rate1 + rate2 + rate3) 
   { 
    return 9;
   } 
   else if (randomNumber >= rate0 + rate1 + rate2 + rate3 
    && randomNumber <= rate0 + rate1 + rate2 + rate3 + rate4) 
   { 
    return 13;
   } 
   else if (randomNumber >= rate0 + rate1 + rate2 + rate3 + rate4 
    && randomNumber <= rate0 + rate1 + rate2 + rate3 + rate4 
     + rate5) 
   { 
    return 17;
   } 
   return -1; 
   } 
   //订单金额随机数
   public static BigDecimal getOrderAmountRandom(double min, double max){
	   int scl =  2;//小数最大位数
	    int pow = (int) Math.pow(10, scl);//指定小数位
	    double s = Math.floor((Math.random() * (max - min) + min) * pow) / pow;
	   return BigDecimal.valueOf(s);

	}
   
   public static String OrderFromRandom() 
   { 
	   /** 
	     * 0出现的概率为%50 
	     */
	   double rate0 = 0.50; 

	   double rate1 = 0.10; 

	   double rate2 = 0.10; 

	   double rate3 = 0.05; 

	   double rate4 = 0.20; 

	   double rate5 = 0.05; 
   double randomNumber; 
   randomNumber = Math.random(); 
   if (randomNumber >= 0 && randomNumber <= rate0) 
   { 
    return "自营平台"; 
   } 
   else if (randomNumber >= rate0 && randomNumber <= rate0 + rate1) 
   { 
    return "天猫"; 
   } 
   else if (randomNumber >= rate0 + rate1 
    && randomNumber <= rate0 + rate1 + rate2) 
   { 
    return "京东"; 
   } 
   else if (randomNumber >= rate0 + rate1 + rate2 
    && randomNumber <= rate0 + rate1 + rate2 + rate3) 
   { 
    return "拼多多"; 
   } 
   else if (randomNumber >= rate0 + rate1 + rate2 + rate3 
    && randomNumber <= rate0 + rate1 + rate2 + rate3 + rate4) 
   { 
    return "线下"; 
   } 
   else if (randomNumber >= rate0 + rate1 + rate2 + rate3 + rate4 
    && randomNumber <= rate0 + rate1 + rate2 + rate3 + rate4 
     + rate5) 
   { 
    return "其他"; 
   } 
   return "其他"; 
   } 
   
   
}
